package se.webbzon.boltzmann.minigame.animation;

import se.webbzon.boltzmann.minigame.sandbox.DefaultSandBoxAnimation;
import se.webbzon.boltzmann.minigame.sandbox.SandBoxAnimatable;

public class FloatAnimation extends DefaultSandBoxAnimation {
	
	// The target of the picture (relative)
	private final double dx, dy;
	
	// The original position of the picture
	private double originalX, originalY;
	
	// The duration and remaining time
	private final int duration;
	private int remaining;
	
	/*============================================================
	Constructors
	============================================================*/
	
	public FloatAnimation(int duration, double dx, double dy) {
		this.dx = dx;
		this.dy = dy;
		this.duration = duration;
		remaining = duration;
	}
	
	/*============================================================
	Public Methods
	============================================================*/

	@Override public void onStepEnd(SandBoxAnimatable picture) {
		if (duration == remaining) {
			originalX = picture.getX();
			originalY = picture.getY();
		}
		if (remaining > 0) {
			remaining--;
			float p = 1 - remaining / (float) duration;
			picture.setPosition(originalX + dx * p, 
								originalY + dy * p);
		} else 
			notifyComplete();
	}

}
